﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.IService;
using System.Data;
using Utility;
using System.Collections;
using System.Data.SqlClient;
using Entity;
namespace DataAccess.Service
{
    public class NetworkPortService:INetworkPortService
    {
        
         public bool updatePortInfor(NetworkPort port)
        {
            bool result = false;
            string commandText = string.Format("update PortInfo set availableMonth=availableMonth+@availableMonth,status=@state where portId=@id");
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("availableMonth", port.AvailableLastMonth),
                new SqlParameter("state", port.Status),
                new SqlParameter("id", port.PortId)
            };
            if (SQLHelper.ExecuteNonQuery(commandText, paras) > 0)
            {
                result = true;
            }
            return result;
        }

        public NetworkPort selectPortInfor(string stuId)
        {
            NetworkPort port = new NetworkPort();
            string commandText = string.Format("select * from PortInfo,StudentAccommodation where stuId=@stuId");
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("stuId", stuId)
            };
            SqlDataReader sdReader = SQLHelper.ExecuteReader(commandText, paras);
            if (sdReader.Read())
            {
                port.Status = Convert.ToString(sdReader["status"]);
                port.AvailableBeginTime = Convert.ToDateTime(sdReader["activateDate"]);
                port.AvailableLastMonth = Convert.ToInt32(sdReader["availableMonth"]);
                port.PortId = Convert.ToString(sdReader["portId"]);
            }
            return port;
        }
    
    }
}
